import type { UseFetchOptions } from 'nuxt/app'

class Request {
    private readonly options

    constructor(options: UseFetchOptions<any> = {}) {
        this.options = options
    }

    request<T>(url: string, options: UseFetchOptions<T> = {}) {
        return useFetch<T>(`${this.options.baseURL}${url}`, { ...this.options, ...options })
    }

    get<T>(url: string, options: UseFetchOptions<T> = {}):any {
        return this.request<T>(url, { ...options, method: 'GET' })
    }

    post<T>(url: string, options: UseFetchOptions<T> = {}) {
        return this.request<T>(url, { ...options, method: 'POST' })
    }
}

export const request = new Request({
    baseURL: 'http://jiaocai-web.dev.multimediapress.cn'
})
